﻿Public Class clsPgdMesGt
    Public Function insert(en As entityPgdMesGt) As Integer
        Dim szSql As String = String.Empty
        Dim rtn As Integer
        DBacs.BeginTransaction()
        Try
            szSql &= "INSERT INTO sf.b_gt_pgd_mes(oper_date, mes_project_code, mes_project_name, support_model, count, material_code, oper_type, type_value, oper_count, validity, status, origin, operator, update_time, pgd_code) "
            szSql &= "VALUES ( ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , (SELECT CURRENT_TIMESTAMP(6)), ?); "
            DBacs.ExecuteUpdateSql(szSql, -1, en.oper_date, en.mes_project_code, en.mes_project_name, en.support_model, en.count, en.material_code, en.oper_type0, en.type_value0, en.oper_count0, en.validity, en.status, en.origin, en.Ope, en.pgd_code0)
            rtn = DBacs.ExecuteUpdateSql(szSql, -1, en.oper_date, en.mes_project_code, en.mes_project_name, en.support_model, en.count, en.note, en.oper_type1, en.type_value1, en.oper_count1, en.validity, en.status, en.origin, en.Ope, en.pgd_code1)
            DBacs.CommitTransaction()
        Catch ex As Exception
            DBacs.RollbackTransaction()
            rtn = -2
        End Try
        Return rtn
    End Function
    Public Function insertMes(en As entityPgdMesGt) As Integer
        Dim szSql As String = String.Empty
        Dim rtn As Integer
        DBacs.BeginTransaction()
        Try
            szSql &= "INSERT INTO sf.b_gt_pgd_mes(oper_date, mes_project_code, mes_project_name, support_model, count, material_code, oper_type, type_value, oper_count, validity, status, origin, operator, update_time, pgd_code) "
            szSql &= "VALUES ( ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , (SELECT CURRENT_TIMESTAMP(6)) , ?); "
            rtn = DBacs.ExecuteUpdateSql(szSql, -1, en.oper_date, en.mes_project_code, en.mes_project_name, en.support_model, en.count, en.material_code, en.oper_type0, en.type_value0, en.oper_count0, en.validity, en.status, en.origin, en.Ope, en.pgd_code)
            DBacs.CommitTransaction()
        Catch ex As Exception
            DBacs.RollbackTransaction()
            rtn = -2
        End Try
        Return rtn
    End Function
    Public Function updateMes(en As entityPgdMesGt) As Integer
        Dim szSql As String = String.Empty
        Dim rtn As Integer
        DBacs.BeginTransaction()
        Try
            szSql &= "update sf.b_gt_pgd_mes set "
            szSql &= " oper_date = ?, mes_project_code = ?, mes_project_name = ?, support_model = ?, count = ?, material_code = ?, oper_type = ?, type_value = ?, oper_count = ?, validity = ?, status = ?, origin = ?, operator = ?, update_time = (SELECT CURRENT_TIMESTAMP(6)) "
            szSql &= " where pgd_code = ?"
            rtn = DBacs.ExecuteUpdateSql(szSql, -1, en.oper_date, en.mes_project_code, en.mes_project_name, en.support_model, en.count, en.material_code, en.oper_type0, en.type_value0, en.oper_count0, en.validity, en.status, en.origin, en.Ope, en.pgd_code)
            DBacs.CommitTransaction()
        Catch ex As Exception
            DBacs.RollbackTransaction()
            rtn = -2
        End Try
        Return rtn
    End Function
    Public Function getListById(sys_id As String) As DataTable
        Dim szSql As String = "SELECT * FROM sf.b_gt_pgd_mes where sys_id = ?"
        Return DBacs.ExecuteSql(szSql, -1, sys_id)
    End Function
    Public Function getList(pgd_code As String) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT * FROM sf.b_gt_pgd_mes where pgd_code = ?"
        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, pgd_code)
        Return dt
    End Function

    Public Function getList(sys_id As Integer) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT * FROM sf.b_gt_pgd_mes where sys_id = ?"
        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, sys_id)
        Return dt
    End Function

    Public Function getList(workshop_id As Integer, validity As String, oper_type As String, type_value As String) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT a.*,prod_spec_id || '  (' || prod_spec_name  || ')'as mst_name FROM sf.b_gt_pgd_mes a "
        szSql &= " left join sf.t_prod_spec b on a.support_model = b.prod_spec_id "
        szSql &= " where a.oper_date = current_date and a.validity = ? and a.oper_type = ? and a.type_value = ?"
        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, workshop_id, validity, oper_type, type_value)
        Return dt
    End Function
    Public Function getList(startTime As String, endTime As String) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT a.*,b.jp_layer_num,b.mould_no,b.prod_spec_name FROM sf.b_gt_pgd_mes a "
        szSql &= " left join sf.t_prod_spec b on a.support_model = b.prod_spec_id "
        szSql &= " where 1 = 1 "
        szSql &= "  and a.oper_type = ?"
        If startTime <> "" Then
            szSql &= "  and a.oper_date >= ?"
        End If
        If endTime <> "" Then
            szSql &= "  and a.oper_date <= ?"
        End If
        szSql &= " ORDER BY a.oper_date ASC"
        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, "0", startTime, endTime)
        Return dt
    End Function
    Public Function selectList(startTime As String, endTime As String, material_code As String) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT a.*,b.jp_layer_num,b.mould_no,b.prod_spec_name FROM sf.b_gt_pgd_mes a "
        szSql &= " left join sf.t_prod_spec b on a.support_model = b.prod_spec_id "
        szSql &= " where 1 = 1 "
        szSql &= "  and a.oper_type = ?"
        If startTime <> "" Then
            szSql &= "  and a.oper_date >= ?"
        End If
        If endTime <> "" Then
            szSql &= "  and a.oper_date <= ?"
        End If
        If material_code <> "" Then
            szSql &= "  and a.material_code = ?"
        End If
        szSql &= " ORDER BY a.oper_date ASC"
        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, "0", startTime, endTime, material_code)
        Return dt
    End Function
    Public Function getList(mis_name As String, startTime As String, endTime As String) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT a.*,b.jp_layer_num,b.mould_no,b.prod_spec_name FROM sf.b_gt_pgd_mes a "
        szSql &= " left join sf.t_prod_spec b on a.support_model = b.prod_spec_id "
        szSql &= " where 1 = 1 "
        szSql &= "  and a.oper_type = ?"
        If mis_name <> "" Then
            szSql &= " and a.mes_project_name like ?"
        End If
        If startTime <> "" Then
            szSql &= "  and a.oper_date >= ?"
        End If
        If endTime <> "" Then
            szSql &= "  and a.oper_date <= ?"
        End If
        szSql &= " ORDER BY a.oper_date ASC"
        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, "0", mis_name, startTime, endTime)
        Return dt
    End Function

    Public Function getList(oper_type As String, mis_name As String, startTime As String, endTime As String) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT a.*,b.jp_layer_num,b.mould_no,b.prod_spec_name FROM sf.b_gt_pgd_mes a "
        szSql &= " left join sf.t_prod_spec b on a.support_model = b.prod_spec_id "
        szSql &= " where 1 = 1 "
        szSql &= " and a.oper_type = ?"
        If mis_name <> "" Then
            szSql &= " and a.mes_project_name like ?"
        End If
        If startTime <> "" Then
            szSql &= "  and a.oper_date >= ?"
        End If
        If endTime <> "" Then
            szSql &= "  and a.oper_date <= ?"
        End If
        szSql &= "  ORDER BY a.oper_date ASC"
        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, oper_type, mis_name, startTime, endTime)
        Return dt
    End Function

    Public Function updatevalidity(sys_id As String, status As String) As Integer
        Dim szSql As String = String.Empty
        Dim rtn As Integer
        Try
            szSql &= "update sf.b_gt_pgd_mes set validity = 0 where sys_id = ? and status = ?"
            rtn = DBacs.ExecuteUpdateSql(szSql, -1, sys_id, status)
        Catch ex As Exception

        End Try
        Return rtn
    End Function
End Class
